package it.unibo.deis.lia.mmhc.spm;

import it.unibo.deis.lia.servicemmhc.clock.ServerClock;

import java.util.Vector;

//classe che conterrà i servizi offerti o quello che vorremo mettere a disposizione in futuro
public class LocalService {

	private Vector<Service> servizi;

	private static LocalService localservice = null;

	public synchronized static LocalService getInstance() {
		if (LocalService.localservice == null) {
			LocalService.localservice = new LocalService();
		}
		return localservice;
	}

	public LocalService() {
		servizi = new Vector<Service>();
	}

	public LocalService(Vector<Service> servizi) {
		this.servizi = servizi;
	}

	public Vector<Service> getServizi() {
		return servizi;
	}

	public void setServizi(Vector<Service> servizi) {
		this.servizi = servizi;
	}

	public void addServizio(Service servizio) {
		servizi.add(servizio);
	}

	public void addServizio(String name, int port) {
		startServerService(name, port);
		servizi.add(new Service(name, port));
	}

	private void startServerService(String name, int port) {
		if (name.equalsIgnoreCase("clock")) {
			ServerClock serverClock = new ServerClock(port);
			serverClock.start();
		}
	}

}
